package com.bac.rentmap.web.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletRequest;

public class CityParser {
    private static Pattern domainPattern = Pattern.compile("www\\.(\\w+)\\.hatu.by");
    
    public static String parseCityFromDomain(ServletRequest request){
        return parseCityFromDomain(request.getServerName());
    }
    
    static String parseCityFromDomain(String domain){
        Matcher matcher = domainPattern.matcher(domain);
        if(matcher.matches()){
            return matcher.group(1);
        }
        return null;
    }
}
